import Vue from "vue";
import Vuex from "vuex";
import common from "@/api/common";
import config_url from "@/utils/config";

Vue.use(Vuex);

const store = new Vuex.Store({
  state: {
    /**
     * 是否需要强制登录
     */
    flashSaleStatus: false,
    versionFlag: config_url.env === "prod" || config_url.env === "test" || config_url.env === "release",
    forcedLogin: false,
    hasLogin: false,
    isCustomer: false,
    config_url,
    userName: "",
    reasons: null, // 取消原因枚举
    userInfo: null,
    opertor: null,
    sItem: null,
    qualifications: [], // 资质枚举
    department: [], // 部门枚举
    position: [], // 岗位枚举
    evolve: [], // 进展枚举
    contactWay: [], // 沟通方式枚举
    contactChannel: [], // 沟通渠道枚举
    intention: [], // 客户意向
    showOrHide: null,
    status: {
      qyrz: {
        10: "待审",
        11: "审核中",
        20: "审核成功",
        30: "审核驳回",
        40: "审核不通过",
      },
    },
    self: [
      {
        key: "全部订单",
        value: [[], [], []],
        num: 0,
        code: "allAmount",
        id: 1,
      },
      {
        key: "待确认订单",
        value: [[10, 20], [], []],
        num: 0,
        code: "unConfirmedAmount",
        id: 2,
      },
      {
        key: "待确认合同",
        value: [[25], [], []],
        num: 0,
        code: "unContractsAmount",
        id: 3,
      },
      {
        key: "待支付",
        value: [[25, 30], [-1, -10], []],
        sampleStatus: [[10], []],
        num: 0,
        code: "unPayAmount",
        id: 4,
      },
      {
        key: "待发货",
        value: [[30], [20], [10]],
        num: 0,
        sampleStatus: [[30], [10]],
        code: "unDeliverAmount",
        id: 5,
      },
      {
        key: "已发货",
        value: [[30], [20], [20]],
        num: 0,
        sampleStatus: [[30], [20]],
        code: "deliveredAmount",
        id: 6,
      },
      {
        key: "已签收",
        value: [[30], [20], [30]],
        num: 0,
        sampleStatus: [[30], [30]],
        code: "signedAmount",
        id: 7,
      },
      {
        key: "已取消",
        value: [[-10], [], []],
        num: 0,
        code: "canceledAmount",
        id: 8,
      },
      {
        key: "交易关闭",
        value: [[-20], [], []],
        num: 0,
        code: "closedAmount",
        id: 9,
      },
    ],
    other: [
      {
        key: "全部订单",
        value: [[], [], []],
        num: 0,
        code: "allAmount",
        id: 1,
      },
      {
        key: "待确认",
        value: [[10, 20], [], []],
        num: 0,
        code: "unConfirmedAmount",
        id: 2,
      },
      {
        key: "待支付",
        value: [[30], [-1, -10], []],
        num: 0,
        code: "unPayAmount",
        id: 4,
      },
      {
        key: "待发货",
        value: [[30], [20], [10]],
        num: 0,
        code: "unDeliverAmount",
        id: 5,
      },
      {
        key: "已发货",
        value: [[30], [20], [20]],
        num: 0,
        code: "deliveredAmount",
        id: 6,
      },
      {
        key: "已取消",
        value: [[-10], [], []],
        num: 0,
        code: "canceledAmount",
        id: 8,
      },
    ],
    sample: [
      {
        key: "全部订单",
        value: [[], [], [], []],
        num: 0,
        code: "allAmount",
        id: 1,
      },
      {
        key: "待确认",
        value: [[20, 30, 40], [], [], []],
        num: 0,
        code: "unConfirmedAmount",
        id: 2,
      },
      {
        key: "待支付",
        value: [[25, 30], [-1, -10], [], [10]],
        num: 0,
        code: "unPayAmount",
        id: 3,
      },
      {
        key: "待发货",
        value: [[30, 20, 25], [20], [10], [30]],
        num: 0,
        code: "unDeliverAmount",
        id: 4,
      },
      {
        key: "已发货",
        value: [[30], [20], [20], [30]],
        num: 0,
        code: "deliveredAmount",
        id: 5,
      },
      {
        key: "已签收",
        value: [[30], [20], [30], [30]],
        num: 0,
        code: "signedAmount",
        id: 6,
      },
      {
        key: "已取消",
        value: [[-10], [], [], []],
        num: 0,
        code: "canceledAmount",
        id: 8,
      },
    ],

    isSample: 0,
    tabbarPages: [],
    getMemberInfo: {},
    giftActivitySwitch: false,
    showInviteIcon: true,
    showIndexAnimation: false,
    todoTask: { visible: false, taskName: "", id: 0, countdown: 0, path: "" }, // 活动任务
  },
  getters: {
    todoTask: state => state.todoTask, // 活动任务
  },
  mutations: {
    setFlashSaleStatus(state, data) {
      state.flashSaleStatus = data;
    },
    login(state, userName) {
      state.userName = userName || "新用户";
      state.hasLogin = true;
    },
    logout(state) {
      state.userName = "";
      state.hasLogin = false;
    },
    setCommon(state, data) {
      state.reasons = data;
    },
    setUserInfo(state, data) {
      state.userInfo = data;
      common.getAddressList().then(res => {
        if (res.status == 1) {
          uni.setStorageSync("addressAll", JSON.stringify(res.data));
        }
      });
    },
    setOpertorList(state, data) {
      state.opertor = data;
    },
    setState(state, data) {
      state[data.key] = data.value;
    },
    setShowOrHide(state, data) {
      state.showOrHide = data;
    },
    setIsSample(state, data) {
      state.isSample = data;
    },
    setIsCustomer(state, data) {
      state.isCustomer = data;
    },
    setTabbarPages(state, data) {
      state.tabbarPages = data;
    },
    setGetMemberInfo(state, data) {
      common.getMemberInfo().then(res => {
        if (res.status == 1) {
          state.getMemberInfo = res.data;
        }
      });
    },
    setGiftActivitySwitch(state, data) {
      common.giftActivitySwitch().then(res => {
        if (res.status == 1) {
          state.giftActivitySwitch = res.data;
        }
      });
    },
    setShowInviteIcon(state, data) {
      state.showInviteIcon = data;
    },
    setShowIndexAnimation(state, data) {
      state.showIndexAnimation = data;
    },
    setTodoTask(state, data) {
      state.todoTask = data;
    },
  },
});

export default store;
